<template>
	<view class="mainpadding">
		<view class="titletext zhonghei textcenter margin_top">实付金额</view>
		<view class="titletext xiaohong fonweight textcenter">￥
			<text class=" xiaohong fonweight textcenter" style="font-size: 70rpx;">{{pay_price}}</text>
		</view>
		<view class="ffffff radius mainpadding margin_top">
			<view class="titletext zhonghei">选择支付方式</view>
			<view class="flexbetween margin_top" @click="pay_type = 10">
				<view class="flexleft">
					<u-icon name="weixin-circle-fill" color="#28C445" size="34"></u-icon>
					<view class="margin_left ershiba xiaohei">微信</view>
				</view>
				<u-icon name="checkmark-circle-fill" color="#FF9341" size="24" v-if="pay_type==10"></u-icon>
				<u-icon name="checkmark-circle-fill" color="#999" size="24"  v-if="pay_type!=10"></u-icon>
			</view>
			<view class=" flexbetween margin_top" v-if="type!=3 && type!=5" @click="pay_type = 30">
				<view class="flexleft">
					<u-icon name="red-packet-fill" color="#ff0000" size="34"></u-icon>
					<view class="margin_left ershiba xiaohei">余额</view>
				</view>
				<u-icon name="checkmark-circle-fill" color="#FF9341" size="24"  v-if="pay_type==30"></u-icon>
				<u-icon name="checkmark-circle-fill" color="#999" size="24"  v-if="pay_type!=30"></u-icon>
			</view>
			<view class=" flexbetween margin_top" v-if="type==5" @click="pay_type = 30">
				<view class="flexleft">
					<u-icon name="red-packet-fill" color="#ff0000" size="34"></u-icon>
					<view class="margin_left ershiba xiaohei">店铺余额</view>
				</view>
				<u-icon name="checkmark-circle-fill" color="#FF9341" size="24"  v-if="pay_type==30"></u-icon>
				<u-icon name="checkmark-circle-fill" color="#999" size="24"  v-if="pay_type!=30"></u-icon>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="payorder">立即支付</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid:"",
				pay_price:"",
				type:1,//1酒店房间订单支付,2商品订单支付,3充值支付,4我的商品订单订单支付，5保证金缴纳
				pay_type:10,//10微信，30余额
				openid:"",
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.listid = data.id
			this.pay_price = data.pay_price
			this.type = data.type
		},
		onShow() {
			// #ifdef MP-WEIXIN
			this.wxLogin()
			// #endif
		},
		methods: {
			payorder(){
				let url = '/api/Hotelordercl/payment'
				let data = {
					id: this.listid,
					openid:this.openid,
					pay_type: this.pay_type
				}
				if(this.type==2){//商品订单支付
					delete data.id
					this.$set(data,"order_pay_no",this.listid)
					url = "/api/order/payment"
				}
				if(this.type==3){//充值
					delete data.id
					delete data.pay_type
					this.$set(data,"pay_price",this.pay_price)
					url = "/api/rechargeorder/rechargeMoney"
				}
				if(this.type==4){//我的商品订单立即支付
					url = "/api/order/nowPay"
				}
				if(this.type==5){//保证金缴纳
					delete data.id
					this.$set(data,"shop_id",this.listid)
					url = "/api/shopcl/rechargeBzj"
				}
				if(this.pay_type==30){
					delete data.openid
				}
				httpRequest.request(url, 'POST', data, false, false, false).then(res => {
					if(res.code==1){
						if(this.pay_type==10){
							this.callPayMent(res.data.wxconfig)
						}else{
							httpRequest.toast(res.msg)
							setTimeout(()=>{
								uni.navigateBack(1)
							},500)
						}
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			callPayMent(val){
				let _this=this;
				  uni.requestPayment({
				    provider: 'wxpay',
				  	timeStamp: val.timeStamp,
				  	nonceStr: val.nonceStr,
				  	package: val.package,
				  	signType: val.signType,
				  	paySign: val.paySign,
				  	success: function (res) {
						// 支付成功
						uni.navigateBack(1)
				  	},
				  	fail: function (err) {
						// 支付失败
						console.log(err,"错误信息");
						if(this.type==2){
							uni.redirectTo({
								url:"/pages_wode/wodedingdan"
							})
						}
				  	}
				  });
			},
			wxLogin() {
				let _this = this
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				uni.login({
					success(res) {
						if (res.code) {
							_this.code = res.code
							uni.setStorageSync('code', res.code);
							httpRequest.request('/api/user/getopenid', 'GET', {
								code:res.code
							}).then(resp => {
								uni.hideLoading()
								_this.openid = resp.data.openid
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
